﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using TTGame;
using CinemaDirector;

/*
 * PlayClipTrigger
 *
 *
 *
 * 依赖：
 *
 * ！不写重复代码！
 * @author TTun
 * @date 9/18/2017 3:20:30 PM
 */
namespace TTGameEngine {
[CutsceneItemAttribute("LT Trigger", "LT Play Clip Trigger", CutsceneItemGenre.ActorItem)]
public class PlayClipTrigger : CinemaActorEvent {
    [Tooltip("xxx_xxx形式的命名规则。以前缀决定Resources下的子路径。")]
    public string audioName;
    public float volume = 1f;
    public bool loop = false;
    [Tooltip("勾选Loop后生效。填0代表播放直到脚本结束。")]
    public float playTime = 0f;

    uint audioKey = 0;

    public override void Trigger(GameObject actor) {
        SkillTL skill = this.GetSkill();
        //fixed:停止技能脚本时，脚本上所有剩余的触发器都会触发一次。
        if(skill.IsStopped()) { return; }

        if(loop == false) {
            AudioExtensions.PlayClip(audioName, actor.transform, volume);
        } else {
            audioKey = AudioExtensions.PlayLoopClip(audioName, actor.transform, playTime, volume);
        }
    }

    public override void Stop(GameObject Actor) {
        AudioExtensions.StopAudioCustom(audioKey);
    }
}

}
